Skip to content

Conversation

@vkarpov15
Copy link
Member

Summary

  • include caster-based refs when building schema metadata so array references are exposed
  • apply the same ref handling for nested schema paths and document fetches to support array elements

Testing

  • not run (not requested)

Codex Task

Copilot AI review requested due to automatic review settings December 19, 2025 01:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances schema metadata extraction to include references for array schema paths by utilizing the caster.options.ref fallback. This ensures that array element references (e.g., arrays of ObjectIds referencing other models) are properly exposed in the schema paths metadata returned by document fetch operations.

Key Changes:

  • Extended ref extraction to check caster.options.ref when options.ref is not available
  • Applied the pattern consistently for both top-level and nested schema paths
  • Updated three document fetching functions: getDocument, getDocuments, and getDocumentsStream

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
backend/actions/Model/getDocumentsStream.js Added caster-based ref fallback for both top-level schema paths and nested schema paths in the streaming document fetch
backend/actions/Model/getDocuments.js Added caster-based ref fallback for both top-level schema paths and nested schema paths in the batch document fetch
backend/actions/Model/getDocument.js Added caster-based ref fallback for top-level schema paths in the single document fetch
Comments suppressed due to low confidence (2)

backend/actions/Model/getDocuments.js:96

  • The schema path building logic (lines 74-96) is duplicated across three files: getDocuments.js, getDocumentsStream.js, and getDocument.js. Consider extracting this into a shared helper function to improve maintainability and ensure consistent behavior across all document fetch operations.
  const schemaPaths = {};
  for (const path of Object.keys(Model.schema.paths)) {
    const schemaType = Model.schema.paths[path];
    schemaPaths[path] = {
      instance: schemaType.instance,
      path,
      ref: schemaType.options?.ref ?? schemaType.caster?.options?.ref,
      required: schemaType.options?.required,
      enum: schemaType.options?.enum
    };
    if (schemaType.schema) {
      schemaPaths[path].schema = {};
      for (const subpath of Object.keys(schemaType.schema.paths)) {
        schemaPaths[path].schema[subpath] = {
          instance: schemaType.schema.paths[subpath].instance,
          path: subpath,
          ref: schemaType.schema.paths[subpath].options?.ref ?? schemaType.schema.paths[subpath].caster?.options?.ref,
          required: schemaType.schema.paths[subpath].options?.required,
          enum: schemaType.schema.paths[subpath].options?.enum
        };
      }
    }
  }

backend/actions/Model/getDocumentsStream.js:86

  • The schema path building logic (lines 64-86) is duplicated across three files: getDocuments.js, getDocumentsStream.js, and getDocument.js. Consider extracting this into a shared helper function to improve maintainability and ensure consistent behavior across all document fetch operations.
  const schemaPaths = {};
  for (const path of Object.keys(Model.schema.paths)) {
    const schemaType = Model.schema.paths[path];
    schemaPaths[path] = {
      instance: schemaType.instance,
      path,
      ref: schemaType.options?.ref ?? schemaType.caster?.options?.ref,
      required: schemaType.options?.required,
      enum: schemaType.options?.enum
    };
    if (schemaType.schema) {
      schemaPaths[path].schema = {};
      for (const subpath of Object.keys(schemaType.schema.paths)) {
        schemaPaths[path].schema[subpath] = {
          instance: schemaType.schema.paths[subpath].instance,
          path: subpath,
          ref: schemaType.schema.paths[subpath].options?.ref ?? schemaType.schema.paths[subpath].caster?.options?.ref,
          required: schemaType.schema.paths[subpath].options?.required,
          enum: schemaType.schema.paths[subpath].options?.enum
        };
      }
    }
  }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vkarpov15 vkarpov15 merged commit ad990f4 into main Dec 21, 2025
25 of 26 checks passed
@vkarpov15 vkarpov15 deleted the codex/add-view-document-link-for-array-refs branch December 21, 2025 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants